package com.emperor.core.logic;

import java.util.List;
import java.util.Map;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

public class ReportDataSource implements JRDataSource {
	private int index = 0;
	private List dataList = null;
	private Map values = null;
	
	public ReportDataSource(List dataList) {
		super();
		this.dataList = dataList;
	}
	
	@Override
	public Object getFieldValue(JRField jrField) throws JRException {
		Object value = null;
		if (values.get(jrField.getName()) != null) {
			value = values.get(jrField.getName());
		}
		return value;
	}

	@Override
	public boolean next() throws JRException {
		if (dataList.size() > 0) {
			if (index < dataList.size()) {
				values = (Map)dataList.get(index);
				index++;
				return true;
			}
		}
		return false;
	}

}
